var e = require("../../utils/utils");

Page({
    data: {
        setting: {},
        show: !1,
        screenBrightness: "获取中",
        keepscreenon: !1,
        SDKVersion: "",
        enableUpdate: !0,
        indexPage: {}
    },
    switchChange: function(e) {
        var t = this, n = e.currentTarget.dataset.switchparam, s = this.data.setting;
        "forceUpdate" === n ? this.data.enableUpdate ? s[n] = (e.detail || {}).value : (s[n] = !1, 
        wx.showToast({
            title: "基础库版本较低，无法使用该功能",
            icon: "none",
            duration: 2e3
        })) : "keepscreenon" === n ? (this.setKeepScreenOn(!this.data.keepscreenon), getApp().globalData.keepscreenon = !this.data.keepscreenon) : s[n] = !(e.detail || {}).value, 
        this.setData({
            setting: s
        }), wx.setStorage({
            key: "setting",
            data: s,
            success: function() {
                t.data.indexPage.reloadInitSetting();
            }
        });
    },
    hide: function() {
        this.setData({
            show: !1
        });
    },
    updateInstruc: function() {
        this.setData({
            show: !0
        });
    },
    onShow: function() {
        var e = this, t = getCurrentPages(), n = t[t.length - 2];
        this.setData({
            keepscreenon: getApp().globalData.keepscreenon,
            indexPage: n
        }), this.ifDisableUpdate(), this.getScreenBrightness(), wx.getStorage({
            key: "setting",
            success: function(t) {
                var n = t.data;
                e.setData({
                    setting: n
                });
            },
            fail: function(t) {
                e.setData({
                    setting: {}
                });
            }
        });
    },
    ifDisableUpdate: function() {
        var t = getApp().globalData.systeminfo.SDKVersion;
        e.cmpVersion(t, "1.9.90") >= 0 ? this.setData({
            SDKVersion: t,
            enableUpdate: !0
        }) : this.setData({
            SDKVersion: t,
            enableUpdate: !1
        });
    },
    getHCEState: function() {
        wx.showLoading({
            title: "检测中..."
        }), wx.getHCEState({
            success: function(e) {
                wx.hideLoading(), wx.showModal({
                    title: "检测结果",
                    content: "该设备支持NFC功能",
                    showCancel: !1,
                    confirmText: "朕知道了",
                    confirmColor: "#40a7e7"
                });
            },
            fail: function(e) {
                wx.hideLoading(), wx.showModal({
                    title: "检测结果",
                    content: "该设备不支持NFC功能",
                    showCancel: !1,
                    confirmText: "朕知道了",
                    confirmColor: "#40a7e7"
                });
            }
        });
    },
    getScreenBrightness: function() {
        var e = this;
        wx.getScreenBrightness({
            success: function(t) {
                e.setData({
                    screenBrightness: Number(100 * t.value).toFixed(0)
                });
            },
            fail: function(t) {
                e.setData({
                    screenBrightness: "获取失败"
                });
            }
        });
    },
    screenBrightnessChanging: function(e) {
        this.setScreenBrightness(e.detail.value);
    },
    setScreenBrightness: function(e) {
        var t = this;
        wx.setScreenBrightness({
            value: e / 100,
            success: function(n) {
                t.setData({
                    screenBrightness: e
                });
            }
        });
    },
    setKeepScreenOn: function(e) {
        var t = this;
        wx.setKeepScreenOn({
            keepScreenOn: e,
            success: function() {
                t.setData({
                    keepscreenon: e
                });
            }
        });
    },
    getsysteminfo: function() {
        wx.navigateTo({
            url: "/pages/systeminfo/systeminfo"
        });
    },
    removeStorage: function(e) {
        var t = this, n = e.currentTarget.dataset.type;
        "setting" === n ? wx.showModal({
            title: "提示",
            content: "确认要初始化设置",
            cancelText: "容朕想想",
            confirmColor: "#40a7e7",
            success: function(e) {
                e.confirm && wx.removeStorage({
                    key: "setting",
                    success: function(e) {
                        wx.showToast({
                            title: "设置已初始化"
                        }), t.setData({
                            setting: {}
                        }), t.data.indexPage.reloadInitSetting();
                    }
                });
            }
        }) : "all" === n && wx.showModal({
            title: "提示",
            content: "确认要删除",
            cancelText: "容朕想想",
            confirmColor: "#40a7e7",
            success: function(e) {
                e.confirm && wx.clearStorage({
                    success: function(e) {
                        wx.showToast({
                            title: "数据已清除"
                        }), t.setData({
                            setting: {},
                            pos: {}
                        }), t.data.indexPage.reloadInitSetting();
                    }
                });
            }
        });
    }
});